getwd()
setwd("/Users/ashleyanderson/Documents/Academia/Grad School/Spring 2010/Gov 2001/HWK")

##Imputation of the revised data

##Reading in the original dataset for imputation
data <- read.csv("C:/Documents and Settings/createdefault/newwomens.csv")
require(Amelia)

##Imputing the revised dataset
a.out <- amelia(data, m=5, ts="year", cs="cty", idvars = c("id","id2"), lags = "laborfemale", sqrts = c("oil_gas_rentPOP", "laborfemale", "logGDPcap", "logGDPcap_sq", "age15_64"))

##Z-scores for the first dataset

data1 <- read.csv("womdats1.csv", header=TRUE)


head(data1)


mean(na.omit(data1$FD_oil))
sd(na.omit(data1$FD_oil))

mean(na.omit(data1$FD_labor))
sd(na.omit(data1$FD_labor))

mean(na.omit(data1$FD_income))
sd(na.omit(data1$FD_income))

mean(na.omit(data1$FD_incomesq))
sd(na.omit(data1$FD_incomesq))

mean(na.omit(data1$FD_age))
sd(na.omit(data1$FD_age))

##Z-scores second dataset

data2 <- read.csv("womdats2.csv", header=TRUE)


head(data2)


mean(na.omit(data2$FD_oil))
sd(na.omit(data2$FD_oil))

mean(na.omit(data2$FD_labor))
sd(na.omit(data2$FD_labor))

mean(na.omit(data2$FD_income))
sd(na.omit(data2$FD_income))

mean(na.omit(data2$FD_incomesq))
sd(na.omit(data2$FD_incomesq))

mean(na.omit(data2$FD_age))
sd(na.omit(data2$FD_age))

##Z-scores third dataset

data3 <- read.csv("womdats3.csv", header=TRUE)


head(data3)


mean(na.omit(data3$FD_oil))
sd(na.omit(data3$FD_oil))

mean(na.omit(data3$FD_labor))
sd(na.omit(data3$FD_labor))

mean(na.omit(data3$FD_income))
sd(na.omit(data3$FD_income))

mean(na.omit(data3$FD_incomesq))
sd(na.omit(data3$FD_incomesq))

mean(na.omit(data3$FD_age))
sd(na.omit(data3$FD_age))


##Z-scores fourth dataset

data4 <- read.csv("womdats4.csv", header=TRUE)


head(data4)


mean(na.omit(data4$FD_oil))
sd(na.omit(data4$FD_oil))

mean(na.omit(data4$FD_labor))
sd(na.omit(data4$FD_labor))

mean(na.omit(data4$FD_income))
sd(na.omit(data4$FD_income))

mean(na.omit(data4$FD_incomesq))
sd(na.omit(data4$FD_incomesq))

mean(na.omit(data4$FD_age))
sd(na.omit(data4$FD_age))

##Z-scores fifth dataset

data5 <- read.csv("womdats5.csv", header=TRUE)


head(data5)


mean(na.omit(data5$FD_oil))
sd(na.omit(data5$FD_oil))

mean(na.omit(data5$FD_labor))
sd(na.omit(data5$FD_labor))

mean(na.omit(data5$FD_income))
sd(na.omit(data5$FD_income))

mean(na.omit(data5$FD_incomesq))
sd(na.omit(data5$FD_incomesq))

mean(na.omit(data5$FD_age))
sd(na.omit(data5$FD_age))

dude <- as.matrix(cbind(data5$cty, data5$year, data5$oil_gas_rentPOP))


##Imputation of the original data

##Reading in the original dataset for imputation
data <- read.csv("C:/Documents and Settings/createdefault/owomen.csv")
require(Amelia)

##Imputing the revised dataset
a.out2 <- amelia(data, m=5, ts="year", cs="cty", idvars = c("id","id2"), lags = "laborfemale", sqrts = c("oil_gas_rentPOP", "laborfemale", "logGDPcap", "logGDPcap_sq", "age15_64"))



### Original dataset z.scores

##First data set

data11 <- read.csv("omdata1.csv", header=TRUE)


head(data11)


mean(na.omit(data11$FD_oil))
sd(na.omit(data11$FD_oil))

mean(na.omit(data11$FD_labor))
sd(na.omit(data11$FD_labor))

mean(na.omit(data11$FD_income))
sd(na.omit(data11$FD_income))

mean(na.omit(data11$FD_incomesq))
sd(na.omit(data11$FD_incomesq))

mean(na.omit(data11$FD_age))
sd(na.omit(data11$FD_age))

##Second dataset

data12 <- read.csv("omdata2.csv", header=TRUE)


head(data12)


mean(na.omit(data12$FD_oil))
sd(na.omit(data12$FD_oil))

mean(na.omit(data12$FD_labor))
sd(na.omit(data12$FD_labor))

mean(na.omit(data12$FD_income))
sd(na.omit(data12$FD_income))

mean(na.omit(data12$FD_incomesq))
sd(na.omit(data12$FD_incomesq))

mean(na.omit(data12$FD_age))
sd(na.omit(data12$FD_age))

##Third Dataset

data13 <- read.csv("omdata3.csv", header=TRUE)


head(data13)


mean(na.omit(data13$FD_oil))
sd(na.omit(data13$FD_oil))

mean(na.omit(data13$FD_labor))
sd(na.omit(data13$FD_labor))

mean(na.omit(data13$FD_income))
sd(na.omit(data13$FD_income))

mean(na.omit(data13$FD_incomesq))
sd(na.omit(data13$FD_incomesq))

mean(na.omit(data13$FD_age))
sd(na.omit(data13$FD_age))

##Fourth Dataset
data14 <- read.csv("omdata4.csv", header=TRUE)


head(data14)


mean(na.omit(data14$FD_oil))
sd(na.omit(data14$FD_oil))

mean(na.omit(data14$FD_labor))
sd(na.omit(data14$FD_labor))

mean(na.omit(data14$FD_income))
sd(na.omit(data14$FD_income))

mean(na.omit(data14$FD_incomesq))
sd(na.omit(data14$FD_incomesq))

mean(na.omit(data14$FD_age))
sd(na.omit(data14$FD_age))

##Fifth dataset

data15 <- read.csv("omdata5.csv", header=TRUE)


head(data15)


mean(na.omit(data15$FD_oil))
sd(na.omit(data15$FD_oil))

mean(na.omit(data15$FD_labor))
sd(na.omit(data15$FD_labor))

mean(na.omit(data15$FD_income))
sd(na.omit(data15$FD_income))

mean(na.omit(data15$FD_incomesq))
sd(na.omit(data15$FD_incomesq))

mean(na.omit(data15$FD_age))
sd(na.omit(data15$FD_age))

##Creating a dummy dataset so that countries can be numerical values (necessary to run time series models in Stata)

poops <- as.matrix(cbind(data15$cty, data15$year, data15$oil_gas_rentPOP))

write.csv(poops, file = "poops.csv")

##### Models were run in Stata using the following commands

## xtregar zlabor zincome zincomesq zoil, fe
## xtregar zlabor zincome zincomesq zoil if id !="KWT" & !="SAU", fe
##xtreg zlabor zincome zincomesq zoil year*, fe


##### Production of the coefficient estimates and the standard errors were done in R, but on a file that I accidentally deleted. 